package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembisk;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembisk.vo.DpItemBiskPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembisk.vo.DpItemBiskRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpitembisk.vo.DpItemBiskSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dpitem.DpItemBiskDO;
import cn.iocoder.yudao.module.erp.service.dpitem.DpItemBiskService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - ERP比什凯克制单货号详情")
@RestController
@RequestMapping("/erp/dp-item-bisk")
@Validated
public class DpItemBiskController {

    @Resource
    private DpItemBiskService dpItemBiskService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP比什凯克制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:create')")
    public CommonResult<Long> createDpItemBisk(@Valid @RequestBody DpItemBiskSaveReqVO createReqVO) {
        return success(dpItemBiskService.createDpItemBisk(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP比什凯克制单货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:update')")
    public CommonResult<Boolean> updateDpItemBisk(@Valid @RequestBody DpItemBiskSaveReqVO updateReqVO) {
        dpItemBiskService.updateDpItemBisk(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP比什凯克制单货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:delete')")
    public CommonResult<Boolean> deleteDpItemBisk(@RequestParam("id") Long id) {
        dpItemBiskService.deleteDpItemBisk(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP比什凯克制单货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:query')")
    public CommonResult<DpItemBiskRespVO> getDpItemBisk(@RequestParam("id") Long id) {
        DpItemBiskDO dpItemBisk = dpItemBiskService.getDpItemBisk(id);
        return success(BeanUtils.toBean(dpItemBisk, DpItemBiskRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP比什凯克制单货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:query')")
    public CommonResult<PageResult<DpItemBiskRespVO>> getDpItemBiskPage(@Valid DpItemBiskPageReqVO pageReqVO) {
        PageResult<DpItemBiskDO> pageResult = dpItemBiskService.getDpItemBiskPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpItemBiskRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP比什凯克制单货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-item-bisk:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpItemBiskExcel(@Valid DpItemBiskPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpItemBiskDO> list = dpItemBiskService.getDpItemBiskPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP比什凯克制单货号详情.xls", "数据", DpItemBiskRespVO.class,
                        BeanUtils.toBean(list, DpItemBiskRespVO.class));
    }

}